package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketCollectExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketCollectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yi
 * @date 2022/10/13 17:23
 */

@Service
public class AdminCollectServiceImpl implements AdminCollectService {

    @Autowired
    MarketCollectMapper marketCollectMapper;
    @Override
    public CommonData<MarketCollect> queryCollect(Integer userId, Integer valueId, BasePageInfo basePageInfo) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketCollectExample marketCollectExample = new MarketCollectExample();
        marketCollectExample.setOrderByClause(basePageInfo.getSort());
        MarketCollectExample.Criteria criteria = marketCollectExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }
        List<MarketCollect> marketCollects = marketCollectMapper.selectByExample(marketCollectExample);
        PageInfo<MarketCollect> marketCollectPageInfo = new PageInfo<>(marketCollects);
        return CommonData.data(marketCollectPageInfo);
    }
}
